﻿using System.Data;
using System.Data.SqlClient;

/// <summary>
/// Descripción breve de CDarDataSet
/// </summary>

namespace consultasSql.consultasVarias
{
    public class CDarDataSet
    {
        public DataSet darDataSet(SqlCommand command)
        {
            DataSet myDS = new DataSet();

            using (SqlConnection objConexion = new SqlConnection(CCadenaConexionSql.cadConexion()))
            {
                try
                {
                    command.Connection = objConexion;

                    SqlDataAdapter MyDA = new SqlDataAdapter();
                    MyDA.SelectCommand = command;

                    if (objConexion.State == ConnectionState.Closed)
                    { objConexion.Open(); }

                    MyDA.Fill(myDS);

                }
                catch { }

                if (objConexion.State == ConnectionState.Open)
                { objConexion.Close(); }

                objConexion.Dispose();
            }

            if (myDS.Tables.Count > 0)
                return myDS;
            else
                return null;

        }

        public DataTable darDataTable(SqlCommand command)
        {
            DataSet ds = darDataSet(command);

            try
            {
                if (ds != null)
                {
                    if (ds.Tables.Count > 0)
                        return ds.Tables[0];
                }
            }
            catch
            {
            }

            return null;
        }
    }
}